package com.Sdebruijn.curriculumvitae.sync.local;

import com.Sdebruijn.curriculumvitae.sync.remote.DownloadListener;
import com.Sdebruijn.curriculumvitae.sync.remote.DownloadTask;

/**
 * Class that encapsulates information about download job.
 */
public class Job {

	/** The remote url. */
	private final String remoteUrl;

	/** The local path. */
	private final String localPath;

	/** The type. */
	private final DownloadTask.Type type;

	/** The listener. */
	private final DownloadListener listener;

	/** The error count. */
	private int errorCount = 0;

	/** The image max size. */
	private final ImageMaxSize imageMaxSize;

	/**
	 * Construct a new Job object.
	 * 
	 * @param url
	 *            The url to the object that need to be downloaded
	 * @param local
	 *            The path to local file where the object should be downloaded
	 * @param taskType
	 *            Type of the object. See {@link DownloadTask.Type}
	 * @param downloadListener
	 *            Listener that is notified when job fails or completes
	 */
	public Job(final String url, final String local, final DownloadTask.Type taskType,
			final ImageMaxSize imageMaxSize, final DownloadListener downloadListener) {
		this.remoteUrl = url;
		this.listener = downloadListener;
		this.localPath = local;
		this.type = taskType;
		this.imageMaxSize = imageMaxSize;
	}

	@Override
	public final boolean equals(final Object o) {
		if (o != null) {
			Job newJob = (Job) o;

			return remoteUrl.equalsIgnoreCase(newJob.getRemote());
		}

		return false;
	}

	@Override
	public final int hashCode() {
		return remoteUrl.hashCode();
	}

	/**
	 * Gets the remote.
	 * 
	 * @return the remote
	 */
	public final String getRemote() {
		return remoteUrl;
	}

	/**
	 * Gets the local.
	 * 
	 * @return the local
	 */
	public String getLocalPath() {
		return localPath;
	}

	/**
	 * Gets the listener.
	 * 
	 * @return the listener
	 */
	public DownloadListener getListener() {
		return listener;
	}

	/**
	 * Gets the type.
	 * 
	 * @return the type
	 */
	public DownloadTask.Type getType() {
		return type;
	}

	/**
	 * Gets the error count.
	 * 
	 * @return the error count
	 */
	public int getErrorCount() {
		return errorCount;
	}

	/**
	 * Sets the error count.
	 * 
	 * @param error
	 *            the new error count
	 */
	public void setErrorCount(final int error) {
		this.errorCount = error;
	}

	/**
	 * @return the imageMaxSize
	 */
	public ImageMaxSize getImageMaxSize() {
		return imageMaxSize;
	}
}
